<?php
/**
 * 배추 모바일 빌더 (Mobile for Gnuboard4)
 *
 * Copyright (c) 2010 Choi Jae-Young <www.miwit.com>
 *
 * 저작권 안내
 * - 저작권자는 이 프로그램을 사용하므로서 발생하는 모든 문제에 대하여 책임을 지지 않습니다. 
 * - 이 프로그램을 어떠한 형태로든 재배포 및 공개하는 것을 허락하지 않습니다.
 * - 이 저작권 표시사항을 저작권자를 제외한 그 누구도 수정할 수 없습니다.
 */

if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가 

$mw_is_list = true;

$tmp_skin_path = $board_skin_path;
$pc_skin_path = "$g4[path]/skin/board/$board[bo_skin]";
$board_skin_path = $pc_skin_path;
if (file_exists("$pc_skin_path/mw.lib/mw.skin.basic.lib.php"))
    include_once("$pc_skin_path/mw.lib/mw.skin.basic.lib.php");
$board_skin_path = $tmp_skin_path;

// 컨텐츠샵 멤버쉽
if (function_exists("mw_cash_is_membership")) {
    $is_membership = @mw_cash_is_membership($member[mb_id], $bo_table, "mp_list");
    if ($is_membership == "no")
        ;
    else if ($is_membership != "ok")
        mw_cash_alert_membership($is_membership);
        //alert("$is_membership 회원만 이용 가능합니다.");
}

// 선택옵션으로 인해 셀합치기가 가변적으로 변함
$colspan = 5;

//if ($is_category) $colspan++;
if ($is_checkbox) $colspan++;
if ($is_good) $colspan++;
if ($is_nogood) $colspan++;

// 제목이 두줄로 표시되는 경우 이 코드를 사용해 보세요.
// <nobr style='display:block; overflow:hidden; width:000px;'>제목</nobr>

// 1:1 게시판
if ($mw_basic[cf_attribute] == "1:1" && !$is_admin) {
    require("$pc_skin_path/mw.proc/mw.list.1n1.php");
}

if ($mw_basic[cf_attribute] == "anonymous") {
    if (strstr($sfl, "mb_id") || strstr($sfl, "wr_name")) {
        alert("익명게시판에서는 아이디 또는 이름으로 검색하실 수 없습니다.");
    }
}

if ($mw_basic[cf_anonymous]) {
    if (strstr($sfl, "mb_id") || strstr($sfl, "wr_name")) {
        alert("익명작성이 가능한 게시판에서는 아이디 또는 이름으로 검색하실 수 없습니다.");
    }
}

// 목록 셔플
if ($mw_basic[cf_list_shuffle]) { // 공지사항 제외 처리
    $tmp_notice = array();
    $tmp_list = array();
    for ($i=0, $m=sizeof($list); $i<$m; $i++) {
        if ($list[$i][is_notice])
            $tmp_notice[] = $list[$i];
        else
            $tmp_list[] = $list[$i];
    }
    shuffle($tmp_list);
    $list = array_merge($tmp_notice, $tmp_list);
}

$list_count = sizeof($list);

$list_id = $vote_id = array();
for ($i=0; $i<$list_count; $i++) { $list_id[] = $list[$i][wr_id]; }

// 설문 아이콘 표시용
$vote_id = array();
if ($mw_basic[cf_vote] && $list_count) {
    $sql = "select wr_id, vt_id from $mw[vote_table] where bo_table = '$bo_table' and wr_id in (".implode(',', $list_id).")";
    $qry = sql_query($sql);
    while ($row = sql_fetch_array($qry)) {
        $vote_id[] = $row[wr_id];
        // 잘못된 설문 db 보완
        $row2 = sql_fetch("select count(*) as cnt from $mw[vote_item_table] where vt_id = '$row[vt_id]'");
        if (!$row2[cnt])
            sql_query("delete from $mw[vote_table] where vt_id = '$row[vt_id]'");
    }
}

// 퀴즈 아이콘 표시용
$quiz_id = array();
if ($mw_basic[cf_quiz] && $mw_quiz && $list_count) {
    $sql = "select wr_id, qz_id from $mw_quiz[quiz_table] where bo_table = '$bo_table' and wr_id in (".implode(',', $list_id).")";
    $qry = sql_query($sql, false);
    while ($row = sql_fetch_array($qry)) {
        $quiz_id[] = $row[wr_id];
    }
}

// 자폭 아이콘 표시용
$bomb_id = array();
if ($mw_basic[cf_bomb_level] && $list_count) {
    $sql = "select wr_id from $mw[bomb_table] where bo_table = '$bo_table' and wr_id in (".implode(',', $list_id).")";
    $qry = sql_query($sql, false);
    while ($row = sql_fetch_array($qry)) {
        $bomb_id[] = $row[wr_id];
    }
}
?>

<style type="text/css">
#mw_mobile .board_top { clear:both; height:30px; border-bottom:1px solid #ddd; }
<? if ($mw_basic['cf_type'] == 'list') {?>
#mw_mobile .board_list {
    list-style:none;
    margin:5px;
    padding:0;
    box-shadow: 0 1px #EBEBEB;
    border-radius: 3px;
    border: 1px solid;
    border-color: #E5E5E5 #D3D3D3 #B9C1C6;
    background-color:#fff;
}
<? } ?>
<? if ($mw_basic['cf_type'] != 'list') {?>
#mw_mobile .board_list { margin:5px; padding:0; }
#mw_mobile .board_list li {
    list-style:none;
    margin:0 0 5px 0;
    padding:0;
    box-shadow: 0 1px #EBEBEB;
    border-radius: 3px;
    border: 1px solid;
    border-color: #E5E5E5 #D3D3D3 #B9C1C6;
    background-color:#fff;
}
<? } ?>
#mw_mobile .board_list li.subject { list-style:none; border-bottom:1px solid #ddd; }
#mw_mobile .board_list li.subject a { font-size:15px; display:block; padding:5px 0 5px 5px; }
#mw_mobile .board_list li.subject div { margin:0 0 5px 0; }
#mw_mobile .board_list li.subject div.thumb { float:left; margin:0 10px 5px 0; border:1px solid #ccc; }
#mw_mobile .board_list li.subject div.block { clear:both; margin:0; padding:0; height:0; font-size:0; line-height:0; }
#mw_mobile .board_list .notice { font:bold 1em tahoma; color:#006699; } 
#mw_mobile .board_list_none  { padding:50px 0 50px 0; text-align:center; border-bottom:1px solid #ddd; }

#mw_mobile .board_list { border-bottom:1px solid #ddd; } 
#mw_mobile .board_list { font-size:1em;  } 
#mw_mobile .board_list .num { color:#999999; text-align:center; }
#mw_mobile .board_list .checkbox { text-align:center; }
#mw_mobile .board_list .name { overflow:hidden; padding:0 0 0 5px; font-size:12px; }
#mw_mobile .board_list .datetime { font:normal 11px tahoma; color:#aaa; padding:0 0 0 5px; }
#mw_mobile .board_list .comment { font-family:Tahoma; font-size:11px; color:#EE5A00; }

#mw_mobile .board_button { clear:both; margin:10px 0 0 5px; }

#mw_mobile .board_page { clear:both; text-align:center; margin:3px 0 0 0; font-size:15px; }
#mw_mobile .board_page { margin:30px 0 30px 0;  }
#mw_mobile .board_page a:link,
#mw_mobile .board_page a:visited,
#mw_mobile .board_page a:active,
#mw_mobile .board_page a:hover { font-size:15px; color:#777; border:1px solid #ddd; padding:5px; }
#mw_mobile .board_page a:hover { background-color:#efefef; }

#mw_mobile .board_search { text-align:center; margin:10px 0 0 0; }
#mw_mobile .board_search .stx { height:21px; border:1px solid #9A9A9A; border-right:1px solid #D8D8D8; border-bottom:1px solid #D8D8D8; }
</style>

<!-- 분류 셀렉트 박스, 게시물 몇건, 관리자화면 링크 -->
<div class="board_top">
    <div style="float:left;">
        <form name="fcategory" method="get" style="margin:0px;">
        <? if ($is_category) { ?>
        <select name=sca onchange="location='<?=$category_location?>'+this.value;">
        <option value=''>전체</option>
        <?=$category_option?>
        </select>
        <? } ?>
        </form>
    </div>
    <div style="float:right;">
        <span id="notice_view">[공지감춤]</span>
        <img src="<?=$board_skin_path?>/img/icon_total.gif" align="absmiddle" border='0'>
        <span style="color:#888; font-weight:bold;"><?=$page?>/<?=number_format($total_page)?> PAGE</span>
    </div>
</div>

<script>
if (get_cookie("mobile_notice_toggle_<?=$bo_table?>")) {
    var sheet = document.createElement('style')
    sheet.innerHTML = "#notice_line { display:none; }";
    document.body.appendChild(sheet);
    $("#notice_view").text("[공지보기]");
}
$("#notice_view").css("cursor", "pointer");
$("#notice_view").css("color", "#888");

$("#notice_view").click(function () {
    $("#notice_line").toggle(function () {
        if ($(this).css("display") != "none") {
            set_cookie("mobile_notice_toggle_<?=$bo_table?>", "", 0, g4_cookie_domain);
            $("#notice_view").text("[공지감춤]");
        }
        else {
            set_cookie("mobile_notice_toggle_<?=$bo_table?>", "1", 720, g4_cookie_domain);
            $("#notice_view").text("[공지보기]");
        }
    });
});
</script>

<!-- 제목 -->
<form name="fboardlist" method="post">
<input type='hidden' name='bo_table' value='<?=$bo_table?>'>
<input type='hidden' name='sfl'  value='<?=$sfl?>'>
<input type='hidden' name='stx'  value='<?=$stx?>'>
<input type='hidden' name='spt'  value='<?=$spt?>'>
<input type='hidden' name='page' value='<?=$page?>'>
<input type='hidden' name='sw'   value=''>

<ul class="board_list">

<?php
$mw_membership = array();
$mw_membership_icon = array();

for ($i=0; $i<count($list); $i++) {

$list[$i][href] = "board.php?bo_table=$board[bo_table]&wr_id={$list[$i][wr_id]}" . $qstr;

// 링크수정
for ($j=1; $j<=$g4[link_count]; $j++) {
    if ($list[$i][link][$j]) {
        $list[$i][link_href][$j] = "$mw_mobile[path]/link.php?bo_table=$bo_table&wr_id={$list[$i][wr_id]}&no=$j";
    }
}

// 댓글감춤
if ($list[$i][wr_comment_hide])
    $list[$i][comment_cnt] = 0;

// 호칭
$list[$i][name] = get_name_title($list[$i][name], $list[$i][wr_name]);

// 자동치환
$list[$i][subject] = mw_reg_str($list[$i][subject]);

// BC코드
$list[$i][subject] = bc_code($list[$i][subject], 0);

// 멤버쉽 아이콘
if (function_exists("mw_cash_membership_icon") && $list[$i][mb_id] != $config[cf_admin])
{
    if (!in_array($list[$i][mb_id], $mw_membership)) {
        $mw_membership[] = $list[$i][mb_id];
        $mw_membership_icon[$list[$i][mb_id]] = mw_cash_membership_icon($list[$i][mb_id]);
        $list[$i][name] = $mw_membership_icon[$list[$i][mb_id]].$list[$i][name];
    } else {
        $list[$i][name] = $mw_membership_icon[$list[$i][mb_id]].$list[$i][name];
    }
}

// 목록 사이드뷰 제거
$name = $list[$i][name];
$name = preg_replace("/<a[^>]+>/i", "", $name);
$name = preg_replace("/<\/a>/i", "", $name);
$list[$i][name] = $name;



// 익명
if ($list[$i][wr_anonymous]) {
    $list[$i][name] = "익명";
    $list[$i][wr_name] = $list[$i][name];
}

// 신고된 게시물
$is_singo = false;
if ($list[$i][wr_singo] && $list[$i][wr_singo] >= $mw_basic[cf_singo_number] && $mw_basic[cf_singo_write_block]) {
    $list[$i][subject] = "신고가 접수된 게시물입니다.";
    $is_singo = true;
}

if ($list[$i]['wr_view_block']) {
    $list[$i]['subject'] = "보기가 차단된 게시물입니다.";
}

// 게시물 아이콘
$write_icon = mw_write_icon($list[$i]);

$list[$i] = mw_list_link($list[$i]);

// sns식 날짜표시
$list[$i][datetime2] = date("Y.m.d H:i", strtotime($list[$i][wr_datetime]));
if ($mw_basic[cf_sns_datetime]) {
    $list[$i][datetime2] = mw_basic_sns_date($list[$i][wr_datetime]);
}

if ($i == 0) {
    $notice_count = 0;
    if ($list[$i][is_notice]) {
        echo "<div id='notice_line'>";
        $notice_line = false;
        $notice_count++;
    }
}
if (!$notice_line && !$list[$i][is_notice] && $notice_count) {
    echo "</div> <!--notice_line-->";
    $notice_line = true;
}

if ($mw_basic[cf_type] != 'list')
{
    $thumb_file = mw_thumb_jpg("$thumb_path/{$list[$i][wr_id]}");
    $source_file = $list[$i][file][0][path]."/".$list[$i][file][0][file];

    $thumb_width = "width='80'";
    $thumb_height = "height='80'";

    if (!is_file($thumb_file) || $list[$i][icon_secret]) {
        $thumb_file = mw_get_noimage();
        //$thumb_width = "width='$mw_basic[cf_thumb_width]'";
        //$thumb_height = "height='$mw_basic[cf_thumb_height]'";
    }
}
?>

<li class="subject">
    <? 
    echo "<a href=\"{$list[$i][href]}\">";

    if ($mw_basic[cf_type] != 'list') {
        ?><div class="thumb"><img src="<?=$thumb_file?>" <?=$thumb_width?> <?=$thumb_height?> align=absmiddle></div><?
    }
    echo "<div>";

    echo $write_icon;
    if (!$list[$i][is_notice] && $mw_basic[cf_attribute] == 'qna') {
        echo "<img src='$board_skin_path/img/icon_qna_{$list[$i][wr_qna_status]}.png' align=absmiddle>&nbsp;";
    }

    echo $list[$i][reply];
    echo $list[$i][icon_reply];
    if ($is_category && $list[$i][ca_name])
        echo "[{$list[$i][ca_name]}] ";

    if ($mw_basic[cf_read_level] && $list[$i][wr_read_level])
        echo "<span class=mw_basic_list_level>[{$list[$i][wr_read_level]}레벨]</span>&nbsp;";

    // 제목스타일
    $style = "";
    if ($mw_basic[cf_subject_style])
        $style .= " style='font-family:{$list[$i][wr_subject_font]}; color:{$list[$i][wr_subject_color]}'";

    ob_start();
    echo " " . $list[$i][icon_update];
    echo " " . $list[$i][icon_new];
    echo " " . $list[$i][icon_file];
    echo " " . $list[$i][icon_link];
    echo " " . $list[$i][icon_hot];
    echo " " . $list[$i][icon_secret];
    $icon = ob_get_contents();
    ob_end_clean();

    if ($list[$i][is_notice])
        echo "<span class='notice'>{$list[$i][subject]} {$icon}</span>";
    else
        echo "<span{$style}>{$list[$i][subject]} {$icon}</span>";
    ?>
    </div>
    <div>
        <? if ($list[$i][wr_comment]) { ?> <span class="comment">댓글 <?=$list[$i][comment_cnt]?></span> <? } ?>
        <? if (!$mw_basic[cf_post_name]) { ?> 
        <? if ($mw_basic[cf_attribute] != "anonymous") { ?>
        <span class="name"> by <?=$list[$i][name]?> </span>
        <? }} ?>
        <span class="datetime"> <?=$list[$i][datetime2]?> </span>
    </div>
    <?
    echo "</a>";
    ?>
    <div class="block"></div>
</li>
<? } // end for ?>
</ul>

<? if (count($list) == 0) { ?> 
    <div class="board_list_none">게시물이 없습니다.</div>
<? } ?>

</form>

<div class="board_button">
    <? if ($write_href) { ?> <input type="button" class="btn btn-default btn-sm" value="글쓰기" onclick="location.href='write.php?bo_table=<?=$bo_table?>'"> <? } ?>
</div>

<div class="board_page">
    <input type="button" value="이전페이지" class="btn btn-default btn-sm"
        onclick="location.href='<?="$_SERVER[PHP_SELF]?bo_table=$bo_table$qstr&page=".($page-1)?>'" <? if ($page==1) echo "disabled";?>>
    <input type="button" value="다음페이지" class="btn btn-default btn-sm"
        onclick="location.href='<?="$_SERVER[PHP_SELF]?bo_table=$bo_table$qstr&page=".($page+1)?>'" <? if ($page>=$total_page) echo "disabled";?>>
</div>

<??>
<!-- 검색 -->
<form name="fsearch" method="get" class="form-horizontal" role="form" style="text-align:center;">
<input type="hidden" name="bo_table" value="<?=$bo_table?>">
<input type="hidden" name="sca"      value="<?=$sca?>">
<input type="hidden" name="sop" value="or">
    <select name="sfl" style="width:100px;">
        <option value="wr_subject">제목</option>
        <option value="wr_content">내용</option>
        <option value="wr_subject||wr_content">제목+내용</option>
        <option value="mb_id,1">회원아이디</option>
        <option value="mb_id,0">회원아이디(코)</option>
        <option value="wr_name,1">글쓴이</option>
        <option value="wr_name,0">글쓴이(코)</option>
    </select>
    <input name="stx" maxlength="15" itemname="검색어" required value='<?=$stx?>' style="width:100px;">
    <input type="submit" class="btn btn-default btn-sm" value="검색">
</form>

<div style="height:50px;"></div>

<script>
if ('<?=$sca?>') document.fcategory.sca.value = '<?=$sca?>';
if ('<?=$stx?>') {
    document.fsearch.sfl.value = '<?=$sfl?>';

    if ('<?=$sop?>' == 'and') 
        document.fsearch.sop[0].checked = true;

    if ('<?=$sop?>' == 'or')
        document.fsearch.sop[1].checked = true;
} else {
    document.fsearch.sop[0].checked = true;
}
</script>


<link type="text/css" href="<?=$pc_skin_path?>/mw.js/ui-lightness/jquery-ui-1.8.19.custom.css" rel="stylesheet" />
<script type="text/javascript" src="<?=$pc_skin_path?>/mw.js/jquery-ui-1.8.19.custom.min.js"></script>

<?php

// 팝업공지
$sql = "select * from $mw[popup_notice_table] where bo_table = '$bo_table' order by wr_id desc";
$qry = sql_query($sql, false);
while ($row = sql_fetch_array($qry)) {
    $row2 = sql_fetch("select * from $write_table where wr_id = '$row[wr_id]'");
    if (!$row2) {
        sql_query("delete from $mw[popup_notice_table] where bo_table = '$bo_table' and wr_id = '$row[wr_id]'");
        continue;
    }
    $view = get_view($row2, $board, $board_skin_path, 255);
    mw_board_popup($view, $html);
}

